package com.dtguai.app.api.controller.user;

import com.dtguai.app.protocol.response.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jasypt.encryption.StringEncryptor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 描述
 *
 * @author guo
 * @date 2021/3/2 15:52
 */
@RestController()
@RequestMapping("/api")
@Api(value = "Jasypt加密解密", tags = {"Jasypt加密解密"})
@AllArgsConstructor
@Slf4j
public class JasyptApi {

    private final StringEncryptor encryptor;

    @ApiOperation(value = "Jasypt加密", notes = "Jasypt加密")
    @PostMapping(value = "/encrypt", produces = "application/json;charset=UTF-8")
    public ApiResponse<String> encrypt() {
        String url = encryptor.encrypt("克隆人上班看片");
        return new ApiResponse<>(url);
    }

    @ApiOperation(value = "Jasypt解密", notes = "Jasypt解密")
    @PostMapping(value = "/decrypt", produces = "application/json;charset=UTF-8")
    public ApiResponse<String> decrypt() {
        String url = encryptor.decrypt("nRf1qoJhL868LegJqFRtcPQRJ3yFrZMej++mgIq1kogAlAN107pSLR2TAwSmWJ9WCAm1vbihk0fnHSF/TBsROw==");
        return new ApiResponse<>(url);
    }
}
